#include "SimpleElementS.h"
#include "LinearEquationGroup.h"
#include "Initial.h"

#include <iostream>
#include <fstream>
#include <string>
int LinearEquationGroupTest()
{
	using namespace std;
	LinearEquationGroup<SimpleElementS> l;
	Matrix<double> m(4,5);

	cout<<"Please input the file name:"<<endl;

	string fileName;
	cin>>fileName;
	ifstream inStream(fileName.c_str());

	if(!inStream)
	{
		cout<<"Can't open the file"<<endl;
		return 1;
	}
	inStream>>m;

	LinearEquationGroup<double> le(m);
	vector<double> r;
	try{
		le.solve(r);
		for (size_t i = 0; i < r.size() ; i++)
		{
			cout<<r[i]<<" ";
		}
	}catch(std::runtime_error& e)
	{
		cout<<e.what()<<endl;
	}
	return 0;
}

int Element37Test()
{
	using namespace std;
	InitialDimen(7,37);
	Matrix<SimpleElementS> matrix(37,37);
	int count = 0;
_initial:
	for (size_t i = 0; i < 37; i++)
	{
		for (size_t j = 0; j < 37; j++)
		{
			matrix(i,j) = rand() % 128;
		}
	}
	try{
		matrix.invert();
	}catch(std::runtime_error& )
	{
		goto _initial;
		count++;
	}
	cout<<count<<endl;
	matrix.resize(37,38);
	for (size_t i = 0; i < 37; i++)
	{
		matrix(i,37) = rand() % 128;
	}
	LinearEquationGroup<SimpleElementS> l(matrix);
	vector<SimpleElementS> result;
	l.solve(result);
	for (vector<SimpleElementS>::iterator it = result.begin();
		it != result.end();
		it++)
	{
		cout<<*it<<" ";
	}
	vector<vector<SimpleElementS> > rr;
	l.solve(rr);
	cout<<endl;
	return 0;
}

// int main()
// {
// //	return LinearEquationGroupTest();
// 	return Element37Test();
// }